package com.example.hospitalmanagement.adapter

import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.recyclerview.widget.RecyclerView
import com.example.hospitalmanagement.R
import com.example.hospitalmanagement.bean.ChargeData

/**
 * 收费项目条目所使用的适配器
 */
class ChargeAdapter(context: Context) :
    RecyclerView.Adapter<ChargeAdapter.ChargeHolder>() {
    private val context = context
    lateinit var dataList: MutableList<ChargeData>
    class ChargeHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val itemIcon: ImageView = itemView.findViewById(R.id.drug_price_items_icon)
        val itemName: TextView = itemView.findViewById(R.id.drug_price_items_name)
        val itemText: TextView = itemView.findViewById(R.id.place_of_origin)
        val itemPrice: TextView = itemView.findViewById(R.id.drug_price_items_price)
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChargeHolder {
        return ChargeHolder(
            LayoutInflater.from(context).inflate(R.layout.drug_price_items, parent, false)
        )
    }


    override fun getItemCount(): Int {
        return dataList.size
    }

    @SuppressLint("SetTextI18n")
    override fun onBindViewHolder(holder: ChargeHolder, position: Int) {
        if (dataList[position].checked) {
            holder.itemIcon.isVisible = true
        } else {
            holder.itemIcon.isGone = true
        }
        holder.itemName.text = dataList[position].itemName
        holder.itemText.text = "类型:${dataList[position].itemType}"
        holder.itemPrice.text = "价格:${dataList[position].itemMomey}元/片数"
    }
}